﻿using Md.Api.Entity.DapperModels.MdDB;

namespace Md.Dapper.Repositories.Md;
/// <summary>
/// 系统用户角色关联仓储
/// </summary>
public class SysUserRoleRep : BaseRep<SysUserRoleModel>
{
    /// <summary>
    /// 通过用户编号获取(系统用户角色关联)列表
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <returns>IEnumerable<SysUserRoleModel></returns>
    public IEnumerable<SysUserRoleModel> GetSysUserRoleListByUserId(long userId)
    {
        string sqlFields = "`id`, `user_id`, `role_id`";

        string sqlWhere = " and `user_id` = @UserId ";

        return QueryList(sqlFields, sqlWhere, new { UserId = userId });
    }

    /// <summary>
    /// 通过用户编号删除(系统用户角色关联)数据
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <returns>int</returns>
    public int DeleteRoleByUserId(long userId)
    {
        string sqlWhere = string.Format(@" and `user_id` = @UserId ");

        return Delete(sqlWhere, new { UserId = userId });
    }
}

